home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / manual / examples / db.c < prev    next >
C/C++ Source or Header  |  1994-02-16  |  1KB  |  53 lines

  1. #include <grp.h>
  2. #include <pwd.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6.  
  7. int
  8. main (void)
  9. {
  10.   uid_t me;
  11.   struct passwd *my_passwd;
  12.   struct group *my_group;
  13.   char **members;
  14.  
  15.   /* Get information about the user ID. */
  16.   me = getuid ();
  17.   my_passwd = getpwuid (me);
  18.   if (!my_passwd)
  19.     {
  20.       printf ("Couldn't find out about user %d.\n", (int) me);
  21.       exit (EXIT_FAILURE);
  22.     }
  23.  
  24.   /* Print the information. */
  25.   printf ("I am %s.\n", my_passwd->pw_gecos);
  26.   printf ("My login name is %s.\n", my_passwd->pw_name);
  27.   printf ("My uid is %d.\n", (int) (my_passwd->pw_uid));
  28.   printf ("My home directory is %s.\n", my_passwd->pw_dir);
  29.   printf ("My default shell is %s.\n", my_passwd->pw_shell);
  30.  
  31.   /* Get information about the default group ID. */
  32.   my_group = getgrgid (my_passwd->pw_gid);
  33.   if (!my_group)
  34.     {
  35.       printf ("Couldn't find out about group %d.\n",
  36.           (int) my_passwd->pw_gid);
  37.       exit (EXIT_FAILURE);
  38.     }
  39.  
  40.   /* Print the information. */
  41.   printf ("My default group is %s (%d).\n",
  42.       my_group->gr_name, (int) (my_passwd->pw_gid));
  43.   printf ("The members of this group are:\n");
  44.   members = my_group->gr_mem;
  45.   while (*members)
  46.     {
  47.       printf ("  %s\n", *(members));
  48.       members++;
  49.     }
  50.  
  51.   return EXIT_SUCCESS;
  52. }
  53.